Skip to content

feat(ai): create, edit and list alerts from the chat (save_alert, list_alerts) - #10122

Closed
dfliess wants to merge 22 commits into
rilldata:mainfrom
dfliess:dfliess/chat-alerts
Closed

dfliess wants to merge 22 commits into
rilldata:mainfrom
dfliess:dfliess/chat-alerts

Conversation

@dfliess

@dfliess dfliess commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Hey @nishantmonu51 @k-anshul,

Third of four stacked PRs, on top of #10121. Draft, to ask for your opinion. Only the commits after #10121's are new here.

We wanted users to be able to say "alert me when net sales drop 10% against the same days last month" in the chat, and get the alert without opening the dialog. So the analyst gets two tools, also offered over MCP. Feel free to modify, adapt or discard it, or suggest changes.

  • save_alert creates an alert for the user, or edits one of their own, as a formula alert (criteria) or an AI alert (condition, from feat: AI alerts judged by the analyst agent #10120). It mirrors the dialog's fields: explore, measure, split by dimension, criteria with and/or, time range and time zone, comparison (previous period, day, week, month, quarter or year), dimension filters (values or "contains", included or excluded), schedule or "when data refreshes", renotify, and email and Slack recipients. It writes the same query the dialog writes, so the alert opens and edits in the dialog like any other.
  • Confirmation. The tool description asks the model to show a short preview and wait for the user to confirm before saving. It's an instruction, not enforced by the tool. The tool requires a session with a user, so it can't run from a service token or on a schedule.
  • Edits pass the alert's name and version and only the fields to change. The result lists what changed, so the model can tell the user.
  • list_alerts lists the user's own alerts with their definition in save_alert's arguments, so the model can edit one without guessing.
  • Explore names. The analyst's tools list metrics views, not explores, so explore also takes a metrics view name and uses its explore when there is exactly one. Otherwise the error names the candidates. Before this, the model passed the metrics view name, failed, and guessed.
  • Filters the tool can't write, like measure filters from the dashboard, are kept untouched when the model edits the filters, and listed apart. There's a TODO where they're kept.
  • AI alerts here depend on feat: AI alerts judged by the analyst agent #10120. If you don't want feat: AI alerts judged by the analyst agent #10120, the condition argument comes out and the rest stands for formula alerts.

We checked our version of it on our own deployment, from the web chat: creating formula and AI alerts, editing them from a new conversation, opening them in the dialog, and a request the dialog handles with "vs previous month".

Things we were not sure about

  • One tool for both kinds. Formula and AI alerts share save_alert, because switching between them in the dialog keeps the data context. Two tools would have simpler arguments.
  • Recipients outside the project see the data with the user's permissions, as in the dialog. The description asks the model to say so in the preview.
  • Measure filters aren't writable yet, only kept.

Some questions

  1. Should the confirmation be enforced by the tool, for example with a two-step call, rather than by the description?
  2. Is MCP the right place for these tools too, or only the web chat?

Happy to rename things or rework it, and just as happy to keep it on our side if you don't want it.


Developed in collaboration with Claude Code

Adds a `develop_personal_canvas` tool to the analyst agent. It runs a sub-agent
with the canvas instructions that saves the dashboard as a personal canvas of
the session's user through a new `write_personal_canvas` tool, which reports
parse and reconcile errors back so the sub-agent can fix them.

Personal canvases are stored by the admin service, so the runtime saves them
through a new internal RPC, `SavePersonalFileForUser`. Only the project's
deployment can call it, the owner must be a user with read access to the
project, annotations in the YAML are dropped, and edits keep the canvas'
sharing state. The tools need the `personal_canvases` feature flag and a user
in the session, and `write_personal_canvas` is only available inside
`develop_personal_canvas`.
Personal canvases are owned by the user rather than stored in the repo, so creating one
doesn't need the edit access the other unforwarded tools require. The runtime still
rejects calls for projects without the personal_canvases feature flag.
The org-level MCP server lists the same tools for every project, so a client only learns
that a project lacks one when it calls it. Instead of passing on the runtime's "unknown
tool" error, say why, and for develop_personal_canvas, that the project doesn't enable
personal canvases.
- Read a personal canvas' parse status only after the project parser has
  pulled and parsed it. Waiting for idle while ignoring hidden resources
  returned before the (hidden) parser finished, so a broken canvas could be
  reported as saved.
- Only the project's primary deployment can save personal files, since they
  live in the prod environment, and the tools are hidden outside prod.
- Edits fail instead of overwriting a canvas the user shared, unshared or
  deleted while it was being saved, using a conditional update.
- Hide the tools from service tokens, which carry a user id but no email.
- Only mention get_canvas to the sub-agent when the client can call it.
- Validate edited names, take the display name from the YAML on edits, and
  require project_id and yaml in the request.
- Reword the MCP error for an unavailable develop_personal_canvas, and
  document the tool.
…ool is available

Conditional updates of virtual files now apply the same 128kb limit as inserts.
The docs say the tool is Rill Cloud only, and the MCP error mentions service tokens.
The agent couldn't find the name of a personal canvas to edit from a new
conversation: it was given the display name, develop_personal_canvas
returned not found and the agent created a duplicate dashboard instead.

list_canvases lists the canvases the user can see, including their own
personal canvases marked with personal: true. Other users' personal
canvases are never listed, even for project admins who can open them.
Move the prompt to a userPrompt method and split it into important and
additional context, as develop_file does. Add the user's memories, so
preferences stated to the analyst also apply to the dashboards it builds.
…oard-from-chat

# Conflicts:
#	proto/gen/rill/admin/v1/api.pb.go
…oard-from-chat

# Conflicts:
#	proto/gen/rill/admin/v1/api.pb.go
#	runtime/drivers/admin.go
#	runtime/testruntime/noopadmin.go
#	runtime/testruntime/testruntime.go
A dashboard the AI saved from the chat did not show in the personal
dashboards list until a full reload: nothing refetched the admin's
ListPersonalFiles, and queries don't refetch on mount or focus, so going
back to the page reused the cached list too.

- The chat tool registry's onResult for develop_personal_canvas, the hook
  update_memory uses, refetches the runtime resources and emits
  personal-files-changed on the event bus. web-admin owns the admin
  query, so a listener mounted by the project layout refetches
  ListPersonalFiles on it. Both use refetchType "all": an invalidated
  query nobody observes is not refetched when it mounts again.
- getPersonalFilteredResources refetches both lists on mount, as the
  alerts and reports lists do, so a dashboard saved away from the page
  (e.g. over MCP) shows up when coming back.
…oard-from-chat

# Conflicts:
#	admin/server/mcp.go
#	proto/gen/rill/admin/v1/api.pb.go
#	runtime/ai/ai.go
…aved on behalf of a user

The sanitizer only dropped the top-level annotations, but the parser applies
prod:, env: and environment_overrides: over them, so the model's YAML could
still share a personal canvas, change its owner or turn off admin_managed.
A name or namespace also registered the canvas under another name than its
file's, which broke the returned link and later edits.

Drop those keys too, and test the sanitized YAML through the parser as a
primary deployment parses it.
…YAML

Alerts and reports created through the API with a resolver serialized its
properties as the protobuf Struct's internals (fields/kind/stringvalue), so
the runtime parsed different properties than it was given.
An alert with the ai resolver has its prompt judged as a condition by the
analyst agent, which ends with a structured verdict. A met condition returns
one row with the verdict's reason and the conversation, so the alert fires;
a malformed verdict or an exhausted tool budget is an evaluation error.
The check runs with the alert's own claims, and notifications show the
reason and link to the conversation.
The data tab switches between criteria and an AI condition written as a
sentence. AI alerts load into and save from the dialog however they were
created, and the alert page and history show the condition and the reason
an AI alert triggered.
Adds SaveAlertForUser, ListAlertsForUser, SaveReportForUser and
ListReportsForUser, and exposes them to the runtime through the admin
service driver. They let the runtime create and edit alerts and reports
for the user of its session, as the alert and report dialogs do.

Only the project's primary deployment can call them, and only for a
user with access to the project. They write the same managed YAML as
CreateAlert and CreateReport, owned by that user, and only edit
alerts and reports the user owns.

An edit is based on the version a list returned, and fails if the
file changed since, so it doesn't overwrite a change made from the
dialog in the meantime. A report that opens with each recipient's own
permissions is rejected if a recipient or option needs the creator's,
with an error that explains the alternative.
…dialog

The dialog waited for the dashboard state decoded from web_open_state
before editing any alert but an AI one. An alert created through the
API may have no web_open_state, so such a formula alert never opened.
Editing builds its values, filters and time controls from the alert's
spec alone, so only creating waits for the dashboard state now.
A comparison of a rill time expression is saved as the expression with
the option's offset, like "offset -1M" for the previous month. Reading
it back had no branch for expressions, so the alert and report dialogs
showed every such comparison as the previous period, and opening an
alert or report on its dashboard did the same. It now takes the option
from the trailing offset; any other expression reads as before.
The alert page labelled a comparison saved as a rill time expression,
like "offset -1M", as the previous period: getComparisonLabel took a
range with neither ISO offset nor duration for one. The criteria named
the comparison from the ISO offset only, falling back to an untranslated
"previous period". Both now read the comparison option from the
expression's offset, as the dialog's mappers do, and the criteria fall
back to the translated previous period.
Adds the save_alert and list_alerts tools to the analyst. They save
alerts through the admin service on behalf of the session's user, as
the alert dialog saves them: a formula alert over the dialog's
MetricsViewAggregation query, or an AI alert judged by the ai
resolver. The user owns them and can keep editing them in the dialog.

An edit starts from the alert as listed and only changes the arguments
it sends, so settings the arguments can't express, like the dashboards'
measure filters or a time range saved as an ISO duration, are kept.
It's based on the version the list returned, and fails if the alert
changed since.

The tools are only offered to users present to confirm what they save,
in prod deployments: not to service tokens, nor to the sessions of AI
reports and alerts.
…ols over MCP

Requests to create or change an alert go to the analyst, which saves
an alert the user owns, unless the user asks for a file in the
project. The org-level MCP server forwards save_alert and list_alerts,
which don't need runtime.EditRepo since the alerts they save aren't
stored in the repo.
@pjain1

pjain1 commented Nov 27, 2026

Copy link
Copy Markdown
Member

Creating alerts from the chat is the most valuable part of this stack, and steering the model towards formula criteria over AI conditions is the right default. We would like a smaller first version.

Create and delete only, no editing. Roughly 60% of the non-test code here supports partial edits: omitted-versus-null argument tracking (sentArgs), versions, the changes diff, decoding the stored query back into arguments, and formula-to-AI conversion. It is also where the problems are. For example:

  • Changing measure on a dialog-created alert leaves the stored sort naming the old measure, which the query then rejects.
  • Sending only a new cron resets the stored time zone.

For the first version:

  • save_alert only creates. Drop name, version, Changes, alert_report_edit.go's patch machinery, and the formula-to-AI conversion. To change an alert, the tool returns its edit link and the user changes it in the dialog.
  • Add delete_alert for the user's own alerts.
  • Keep list_alerts, but slim: name, display name, explore, a one-line condition and the edit URL, read from the runtime catalog, not through admin. The model needs it to find the alert to link to or delete.

Confirmation must be enforced. Recipients can be any address and see the data with the owner's permissions, and the only guard is the tool description. A prompt injection through data values or an external MCP tool could create an alert that mails data out. Please enforce this in code. Two options:

  • Default recipients to the user and reject recipients outside the project.
  • Have the tool return a proposal that the web chat confirms with a click.

The same applies to delete.

AI alerts. The scheduling limits on #10120 apply here: a condition requires a cron schedule of at most once an hour, with no data-refresh trigger.

Smaller simplifications.

  • Require an explore name and drop the metrics-view-name fallback in validExplore.
  • Emit comparisons as Rill time offsets only, and drop the legacy ISO branch.
  • previousCompletePresets is a Go copy of the dialog's PreviousCompleteRangeMap; it goes away with the conversion code.
  • The "dialog-saved" test fixtures are hand-typed and lack the sort the dialog always writes. Please add one test that creates an alert through the real admin service, so the YAML, parser and reconcile path is covered.

Before editing comes back. We would want these in place first, as separate work:

  1. Alerts move from query_args_json to resolvers, including the dialog reading and writing resolver properties, and export attachments working for resolvers other than legacy_metrics. save_alert could then pass through the query shape query_metrics_view already uses, with no need to rebuild the dialog's aggregation request in Go.
  2. feat(ai): let the analyst create and edit the user's personal dashboards #10030's trust model is settled.
  3. Confirmation is enforced as above.

Developed in collaboration with Claude Code

@nishantmonu51

Copy link
Copy Markdown
Collaborator

I just raised a follow-up that handles the review comments: #10233. @pjain1 please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants